package com.onlinemart.controller;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.Properties;

public class ConnectionFactory {
	public static String url;
	public static Properties properties;
	public static Driver driver;
	public static String user;
	public static String password;
	
	public static Connection getConnection()
	{
		try
		{
			InputStream inputStream = ConnectionFactory.class.getClassLoader().getResourceAsStream("/resources/application.properties");
			properties=new Properties();
			properties.load(inputStream);
			String driver = properties.getProperty("driver");
			String url = properties.getProperty("url");
			user= properties.getProperty("user");
			password = properties.getProperty("password");
			Class.forName(driver);
			return DriverManager.getConnection(url, user, password);

		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new RuntimeException("Error in loding ConnectionFactory");
		}
	}
}
